<!DOCTYPE html>
<html>

<head>
    <title>我的收藏</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="../js/common.js"></script>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            //当前用户id
            var userId = user.id;
            var params = getParams();
            //文章类型
            var type = params.type;
            //当前页
            var currentPage = 1;
            //总页数
            var pages;
            //[] 数组,一个容器 将每次拉倒底部查询的每页数据 数组都存放在里面
            var travelData = [];
            //变量表示 当前页是否已经在查询中 如果是 则不再查询,避免ajax的异步请求发送重复
            var loading = false;//查询状态

            function query() {
                //如果当前为正在查询 则说明ajax已经发送 不需要重复发送
                if (loading) {
                    return;
                }
                //每次在发送ajax前,将查询状态改为正在查询,
                loading = true;
                $.get("/collect/list/count", {currentPage: currentPage, userId: userId, type: type}, function (data) {
                    //将查询出来的需要的数据的数组放到容器中
                    $.merge(travelData, data.list);
                    //render-loop="list"时 会找叫list的属性,所以需要将数据数组转为json对象的list属性
                    var json = {list: travelData};
                    //判断收藏有没有数据
                    if (data.total != 0) {
                        //有数据就渲染
                        $(".collect").renderValues(json, {
                            'getHref': function (item, value) {
                                if (type == 1) {
                                    $(item).attr("href", "/strategyCatalogs.html?id=" + value);
                                } else if (type == 2) {
                                    $(item).attr("href", "/travelContent.html?id=" + value);
                                } else if (type == 3) {
                                    $(item).attr("href", "/newsContent.html?id=" + value);
                                }
                            }
                        })
                        pages = data.pages;
                        currentPage++;
                        loading = false;
                    } else {
                        //没数据就显示文字提示
                        $(".collect").html("您没有任何收藏.");
                    }
                })
            }

            query();

            $(window).scroll(function () {
                if (($(document).scrollTop() + $(window).height() + 1) >= $(document).height()) {
                    if (currentPage <= pages) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '我是有底线的!',
                            autoClose: 1000,
                            position: 'bottom'
                        });
                    }
                }
            });
        })
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span id="supTitle"></span>
        </div>
        <div class="col"></div>
    </div>
</div>
<div class="container collect">
    <dl class="list" render-loop="list">
        <a render-key="list.id" render-fun="getHref">
            <h6 class="title" render-html="list.title" align="center"></h6>
            <img render-src="list.coverUrl" style="width: 100%">
        </a>
    </dl>
</div>


</body>

</html>